package com.hall.items.repo;

import com.hall.items.aggr.MyWeapon;
import dml.game.weapon.repo.WeaponRepository;
import erp.mongodb.MongodbRepository;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

public class MyWeaponRepository extends MongodbRepository<MyWeapon, Long> implements WeaponRepository<MyWeapon, Long> {
    public MyWeaponRepository(MongoTemplate mongoTemplate) {
        super(mongoTemplate);
    }

    public Long findMaxId() {
        if (mongoTemplate == null) {
            return null;
        }
        Query query = new Query();
        query.with(Sort.by(Sort.Direction.DESC, "_id"));
        query.limit(1);
        MyWeapon maxEtt = mongoTemplate.findOne(query, MyWeapon.class);
        if (maxEtt == null) {
            return null;
        }
        return (Long) maxEtt.getId();
    }

}
